CMAKE_MINIMUM_REQUIRED(VERSION 3.9.6)

PROJECT(FastWindingNumber)
SET(CMAKE_CXX_STANDARD 11)

SET(CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake)

IF (NOT TBB_FOUND)
    FIND_PACKAGE(TBB REQUIRED)

    ADD_LIBRARY(TBB::tbb INTERFACE IMPORTED)
    TARGET_INCLUDE_DIRECTORIES(TBB::tbb SYSTEM INTERFACE ${TBB_INCLUDE_DIRS})
    TARGET_LINK_LIBRARIES(TBB::tbb INTERFACE
        ${TBB_LIBRARIES})

    ADD_LIBRARY(TBB::tbbmalloc INTERFACE IMPORTED)
    TARGET_INCLUDE_DIRECTORIES(TBB::tbbmalloc SYSTEM INTERFACE
        ${TBB_MALLOC_INCLUDE_DIRS})
    TARGET_LINK_LIBRARIES(TBB::tbbmalloc INTERFACE
        ${TBB_MALLOC_LIBRARIES})

    ADD_LIBRARY(TBB::tbbmalloc_proxy INTERFACE IMPORTED)
    TARGET_INCLUDE_DIRECTORIES(TBB::tbbmalloc_proxy SYSTEM INTERFACE
        ${TBB_MALLOC_PROXY_INCLUDE_DIRS})
    TARGET_LINK_LIBRARIES(TBB::tbbmalloc_proxy INTERFACE
        ${TBB_MALLOC_PROXY_LIBRARIES})
ENDIF (NOT TBB_FOUND)

SET(SRC_FILES
    UT_Array.cpp
    UT_SolidAngle.cpp)
SET(INC_FILES
    SYS_Math.h
    SYS_Types.h
    UT_Array.h
    UT_ArrayImpl.h
    UT_BVH.h
    UT_BVHImpl.h
    UT_FixedVector.h
    UT_ParallelUtil.h
    UT_SmallArray.h
    UT_SolidAngle.h
    VM_SIMD.h
    VM_SSEFunc.h)

ADD_LIBRARY(FastWindingNumber SHARED ${SRC_FILES} ${INC_FILES})
TARGET_LINK_LIBRARIES(FastWindingNumber PUBLIC TBB::tbb TBB::tbbmalloc)

ADD_SUBDIRECTORY(tests EXCLUDE_FROM_ALL)

INSTALL(TARGETS FastWindingNumber
    LIBRARY DESTINATION lib
    ARCHIVE DESTINATION lib
    )
INSTALL(FILES ${INC_FILES}
    DESTINATION include/FastWindingNumber)
